package com.nero.service.impl;

import com.nero.bean.PO.TbAdmin;
import com.nero.bean.PO.TbAdminExample;
import com.nero.dao.TbAdminMapper;
import com.nero.service.IAdminService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by Nero on 18/8/6.
 */
@Service
public class AdminServiceImpl implements IAdminService {
    @Resource
    TbAdminMapper tbAdminMapper;

    private static Logger logger = LogManager.getLogger(AdminServiceImpl.class);

    @Override
    public TbAdmin login(TbAdmin form) {
        TbAdminExample example = new TbAdminExample();
        TbAdminExample.Criteria c = example.createCriteria();
        c.andPasswordEqualTo(form.getPassword());
        c.andUsernameEqualTo(form.getUsername());
        List<TbAdmin> found = tbAdminMapper.selectByExample(example);
        if (found.size() == 0) {
            logger.info("登录失败");
            return null;
        } else {
            logger.info("登录成功");
            return found.get(0);
        }
    }
}
